#include<match.h>

void match::getnode(vector<Node_C*>& p_node)
{
	p_node=node;
}

void match::mktable(vector<Node_C*> cnode,vector<Node_C*> inode,int n,vector<int> & fout)
{
	vector<vector<int> > fin;
        int c,count;
        for(unsigned int i=0;i<n;i++)
        {
                vector<int> x;
                count=0;
                c=0;
                for(unsigned int j=0;j<pow(2,n);j++)
                {
                        if(count<pow(2,i))
                                count++;
                        else
                        {
                                if(c==0)
                                        c=1;
                                else
                                        c=0;
                                count=1;
                        }
                        x.push_back(c);
                }
                fin.push_back(x);
        }
	for(unsigned int i=0;i<pow(2,n);i++)
        {
                for(unsigned int j=0;j<fin.size();j++)
                {
                        inode[j]->data=fin[j][i];
                }
                for(unsigned int j=0;j<cnode.size();j++)
                {
                        if(cnode[j]->id==0)
                        {
                                if(cnode[j]->input[0]->data)
                                        cnode[j]->data=0;
                                else
                                        cnode[j]->data=1;
                        }
                        else if(cnode[j]->id==1)
                        {
                                if(cnode[j]->input[0]->data&&cnode[j]->input[1]->data)
                                        cnode[j]->data=1;
                                else
                                        cnode[j]->data=0;
                        }
                        if(j==cnode.size()-1)
                                fout.push_back(cnode[j]->data);
                }
        }

}

